﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace LINQToolKit
{
    internal static class ObjectHelper
    {
        public static void InjectProperties(this object entity, IDictionary<string, string> properties)
        {
            ObjectHelper.InjectProperties(entity, properties,
                BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.IgnoreCase);
        }

        public static void InjectProperties(
            this object entity, IDictionary<string, string> properties, BindingFlags binding)
        {
            if (properties == null || entity == null)
            {
                return;
            }

            var entityType = entity.GetType();
            foreach (var key in properties.Keys)
            {
                var property = entityType.GetProperty(key, binding);
                property.SetValue(entity, properties[key], null);
            }
        }
    }
}
